using System;
using System.Configuration;
using System.Data.SqlClient;
using Entities;
using DAL;
using System.Collections.Generic;
using System.Text;

namespace BUS
{
    public class tbSanPhamBUS
    {
        public static int Insert(tbSanPhamEntities sanpham)
        {
            tbSanPhamDAL sanphamDAL = new tbSanPhamDAL();
           return sanphamDAL.Insert(sanpham);
        }
        public static void Update(tbSanPhamEntities sanpham)
        {
            tbSanPhamDAL sanphamDAL = new tbSanPhamDAL();
           sanphamDAL.Update(sanpham);
        }
        public static void Delete(int iD)
        {
            tbSanPhamDAL sanphamDAL = new tbSanPhamDAL();
            sanphamDAL.Delete(iD);
        }
        public static tbSanPhamEntities.tbSanPhanEntitiesCollection Get(string where,int pageindex, int pagesize,string orderby, string orderdirection,out int total)
        {
            tbSanPhamDAL sanphamDAL = new tbSanPhamDAL();
            return sanphamDAL.Get(where, pageindex, pagesize, orderby,orderdirection, out total);
        }
        public static tbSanPhamEntities.tbSanPhanEntitiesCollection GetAll()
        {
            int total = 0;
           tbSanPhamDAL sanphamDAL = new tbSanPhamDAL();
            return sanphamDAL.Get("where 1=1", 0, 0,tbSanPhamEntities.tbSanPhanEntitiesColumns.MaSP.ToString(),"ASC", out total);
        }
        public static tbSanPhamEntities GetByID(int iD)
        {
            int total = 0;
            tbSanPhamDAL sanphamDAL = new tbSanPhamDAL();
            tbSanPhamEntities.tbSanPhanEntitiesCollection sanphamCollection = sanphamDAL.Get("where " + tbSanPhamEntities.tbSanPhanEntitiesColumns.MaSP.ToString() + "=" + iD.ToString(),0, 0,tbSanPhamEntities.tbSanPhanEntitiesColumns.MaSP.ToString(), "ASC", out total);
            if (sanphamCollection.Count > 0)
                return sanphamCollection[0];
            return null;
        }
    }
}
